package com.mostka.wsrpc.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.mostka.rpc.client.WebSocketRpc;
import com.mostka.rpc.client.WsRpcOnStateHandler;
import com.mostka.wsrpc.shared.TestObject;
import com.mostka.wsrpc.shared.TestObject2;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GwtWsExample implements EntryPoint {


	public void onModuleLoad() {
		
		if (WebSocketRpc.isSupported()==false){
			Window.alert("Web socket is not suported");
		}
		WebSocketRpc webSocket = new WebSocketRpc("defaultChannel");
		
		GWT.create(TestObject2.class);
		TestObject obj = GWT.create(TestObject.class);
		final TestWsServerAsync server = GWT.create(TestWsServer.class);
			
		obj.bbb[0]=5;
		obj.aaa[1]="jojo";
		obj.object=null;
		final TestObject obj2 = (TestObject)GWT.create(TestObject.class);

		obj.object= new TestObject[2];
		obj.object[0]=obj2;
		obj2.bbb[1]=6;
		obj2.aaa[0]="obj2";
		
		final TestObject obj3 = GWT.create(TestObject.class);

		
		TestWsClient client = new TestWsClient() {
            @Override
            public void clientMethod(TestObject testObject) {
                Window.alert("clientMethod " +testObject.ddd[0]+","+testObject.ddd[1]);
            }

            @Override
            public void testMethod(int i, String s, double d, char ch, long l, byte b, boolean bo, short sh) {
                Window.alert(","+i+","+s+","+d+","+ch+","+l+","+b+","+bo+","+sh);
            }

            @Override
            public void testMethod(int[] i, String[] s, double[] d, char[] ch, long[] l, byte[] b, boolean[] bo, short[] sh) {
                Window.alert("testMethodArr");
            }
        };


		webSocket.join(server, client, new WsRpcOnStateHandler() {
			public void onJoin() {
				server.serverMethod("string", 15, obj3);
				//server.serverMethod("string5", 10, obj2);
			}
			public void onClose() {
			}
			public void onError(String data) {
			}
		});
	}
}
